package com.example.hospitalsystem.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.hospitalsystem.pojo.entity.Doctor;
import com.example.hospitalsystem.pojo.entity.Patient;
import com.example.hospitalsystem.pojo.entity.Prescription;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DoctorMapper extends BaseMapper<Doctor> {

    /**
     * 删除医生接诊表数据
     * @param consultationId
     */
    @Delete("delete from consultation where consultation_id = #{consultationId}")
    void deletePatientByConsultationId(Integer consultationId);

    /**
     * 根据患者id删除该患者处方表数据
     * @param patientId
     */
    @Delete("delete from prescription where patient_id = #{patientId}")
    void deletePrescriptionByPatientId(Integer patientId);

    /**
     * 根据处方id删除处方关联的患者药品数据
     * @param prescriptionId
     */
    @Delete("delete from prescription_pharmacy where prescription_id = #{prescriptionId}")
    void deletePatientByPrescriptionId(Integer prescriptionId);

    /**
     * 从接诊表的患者名查询患者信息
     * @param patientName
     * @return
     */
    @Select("select * from patient where patient_name = #{patientName}")
    Patient getPrescriptionByPatientName(String patientName);

    /**
     * 根据患者id查询Prescription表数据
     * @param patientId
     * @return
     */
    @Select("select * from prescription where patient_id = #{patientId}")
    Prescription getPrescriptionById(Integer patientId);


    @Select("select * from doctor where doctor_name like concat('%',#{key},'%')")
    List<Doctor> search(String key);
}
